//
//  DataAccess.m
//  HelloK3
//
//  Created by nam trnam on 4/26/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "DataAccess.h"


@implementation DataAccess

-(id)initDataAccess {
    self = [super init];
    return self;
}

-(MapData*)getMapDataWith:(NSString*)xmlPath {
    
    NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:xmlPath];
    NSData *xmlData = [NSData dataWithContentsOfFile:path];
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData];    
	MapDataParser *parser = [[MapDataParser alloc] initMapData];
	
	//Set delegate
	[xmlParser setShouldResolveExternalEntities:YES];
	[xmlParser setDelegate:parser];
	
	
	//NSLog(@"DataAccessing data");
	//Start parsing the XML file.
	BOOL success = [xmlParser parse];
	
	if(success) {
        return parser.mapData;
	}
	else {
		
	//	NSLog(@"Error DataAccess data");
		return nil;
	}
}

-(NSMutableArray *)getListMapWithListMapXmlFile:(NSString *)xmlFile {
    NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:xmlFile];
    NSData *xmlData = [NSData dataWithContentsOfFile:path];
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData];    
	MapDataParser *parser = [[MapDataParser alloc] initMapData];
	
	//Set delegate
	[xmlParser setShouldResolveExternalEntities:YES];
	[xmlParser setDelegate:parser];
	
	
	//NSLog(@"DataAccessing data");
	//Start parsing the XML file.
	BOOL success = [xmlParser parse];
	
	if(success) {
        return parser.mapData;
	}
	else {
		
        //	NSLog(@"Error DataAccess data");
		return nil;
	}
}

//-(NSMutableDictionary*)getMapData{
//    
//    NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Map.xml"];
//    NSData *xmlData = [NSData dataWithContentsOfFile:path];
//    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData];    
//	SettingInfo *parser = [[SettingInfo alloc] initSystemSettingParser];
//	
//	//Set delegate
//	[xmlParser setShouldResolveExternalEntities:YES];
//	[xmlParser setDelegate:parser];
//	
//	
//	//NSLog(@"DataAccessing data");
//	//Start parsing the XML file.
//	BOOL success = [xmlParser parse];
//	
//	if(success) {
//		return parser.systemDic;
//	}
//	else {
//		
//		NSLog(@"Error DataAccess data");
//		return nil;
//	}
//}


    
@end
